package com.yunji.app.system;

import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.domain.SysDictDataDO;
import com.yunji.common.utils.StringUtils;
import com.yunji.system.service.ISysDictDataService;
import com.yunji.system.service.ISysDictTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package com.yunji.app.system
 * @FileName GateWayDictDataController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * @Company com
 * @Version 1.0
 * @Since JDK1.8.0_201
 * @CreateTime 2024-06-10 22:48:18
 * @Description 移动端-数据字典信息
 * @Modification History
 * Author					History Time			Version			Description
 * -------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-06-10 22:48:18		1.0				1.0
 */
@Api(tags = "移动端-数据字典信息")
@RestController
@RequestMapping("/gateway/dict/data")
public class GateWayDictDataController extends BaseController {
    @Resource
    private ISysDictDataService dictDataService;

    @Resource
    private ISysDictTypeService dictTypeService;

    @GetMapping("/list")
    @ApiOperation("数据字典列表")
    public Response<List<SysDictDataDO>> list(SysDictDataDO dictData) {
        List<SysDictDataDO> list = dictDataService.selectDictDataList(dictData);
        return ResponseHelper.successWithPage(list);
    }

    /**
     * 查询字典数据详细
     */
    @ApiOperation("查询字典数据详细")
    @GetMapping(value = "/{dictCode}")
    public Response<SysDictDataDO> getInfo(@PathVariable Long dictCode) {
        return ResponseHelper.success(dictDataService.selectDictDataById(dictCode));
    }

    /**
     * 根据字典类型查询字典数据信息
     */
    @ApiOperation("根据字典类型查询字典数据信息")
    @GetMapping(value = "/type/{dictType}")
    public Response<List<SysDictDataDO>> dictType(@PathVariable String dictType) {
        List<SysDictDataDO> data = dictTypeService.selectDictDataByType(dictType);
        if (StringUtils.isNull(data)) {
            data = new ArrayList<>();
        }
        return ResponseHelper.success(data);
    }

    @ApiOperation("查询字典类型详细")
    @GetMapping(value = "/containerType")
        public Response<List<SysDictDataDO>>    containerType() {
        SysDictDataDO dictData = new SysDictDataDO();
        dictData.setDictType("container_type");
        List<SysDictDataDO> list = dictDataService.selectDictDataList(dictData);
        return ResponseHelper.successWithPage(list);
    }
}
